package org.ldx.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.ldx.lotterysystem.dao.dataobject.Encrypt;
import org.ldx.lotterysystem.dao.dataobject.UserDo;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select count(*) from user where email = #{mail}")
    int countByMail(String mail);
    @Select("select count(*) from user where phone_number = #{phoneNumber}")
    int countByPhone(@Param("phoneNumber") Encrypt encrypt);
    @Insert("insert into user (user_name,email,phone_number,password,identity) values " +
            "(#{userName},#{email},#{phoneNumber},#{password},#{identity})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(UserDo userDo);
    @Select("select * from user where phone_number = #{encrypt}")
    UserDo selectByPhoneNumber(Encrypt encrypt);
    @Select("select * from  user where email = #{loginName}")
    UserDo selectByMail(String loginName);
    @Select("<script> select * from user " +
            "<if test =\"userIdentity!=null\"> " +
            "where identity = #{userIdentity}</if> order by id desc </script>")
    List<UserDo> selectUsrListByIdentity(String userIdentity);

    @Select("<script>" +
            " select id from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<Long> selectExistByIds(@Param("items") List<Long> ids);
    @Select("<script>" +
            " select * from user" +
            " where id in" +
            " <foreach item='item' collection='items' open='(' separator=',' close=')'>" +
            " #{item}" +
            " </foreach>" +
            " </script>")
    List<UserDo>  batchSelectById(@Param("items") List<Long> collect);
}
